package com.itheima.tlais_web_management.controller;

import com.itheima.tlais_web_management.pojo.Emp;
import com.itheima.tlais_web_management.pojo.PageBean;
import com.itheima.tlais_web_management.pojo.Result;
import com.itheima.tlais_web_management.pojo.Student;
import com.itheima.tlais_web_management.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;


    @GetMapping("/student")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String name,Integer educationId,String number,Integer classId)
                       {

        log.info("分页查询：参数{},{},{},{},{},{}",page,pageSize,name,educationId,number,classId);
        PageBean pageBean = studentService.list(page,pageSize,name,educationId,number,classId);

        return Result.success(pageBean);
    }

    @GetMapping("/student/{id}")
    public Result getbyid(@PathVariable Integer id){
        log.info("根据 id 查询学生信息：{}",id);

        Student student = studentService.getbyid(id);

        return Result.success(student);
    }

    @PutMapping("/student")
    public Result update(@RequestBody Student student){
        log.info("修改员工信息：{}",student);

        studentService.update(student);

        return Result.success();
    }

    @PostMapping("/student")
    public Result save(@RequestBody Student student){
        log.info("添加员工：{}",student);

        studentService.save(student);

        return Result.success();
    }

    @DeleteMapping("/student/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("根据 id 批量删除学生{}",ids);

        studentService.delete(ids);

        return Result.success();
    }


}
